package org.goyo.main.services.base.impl;

import java.util.Date;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.goyo.common.baseBean.Constants;
import org.goyo.common.exception.DBException;
import org.goyo.common.exception.ServiceException;
import org.goyo.common.utils.DateUtils;
import org.goyo.common.utils.Pager;
import org.goyo.main.domain.dao.base.ISuppliersNatureDao;
import org.goyo.main.domain.entity.BaseObject;
import org.goyo.main.domain.entity.base.SuppliersNature;
import org.goyo.main.domain.entity.system.SysUser;
import org.goyo.main.services.BaseService;
import org.goyo.main.services.base.ISuppliersNatureService;
import org.goyo.main.web.controller.system.SessionUtil;
import org.springframework.stereotype.Service;

@Service
@Transactional
public class SuppliersNatureServiceImpl extends BaseService implements ISuppliersNatureService{
	
	@Resource
	private ISuppliersNatureDao suppliersNatureDao;

  @Override
  public BaseObject saveOrUpdateInfo(SuppliersNature info) throws DBException, ServiceException {
    String uuid = null;
    String date = DateUtils.parseDate("yyyy-MM-dd", new Date());
    SysUser user = (SysUser)SessionUtil.getAttribute("user");
    //保存用户数据
    if(info.getUuid() == null || "".equals(info.getUuid())){
        info.setUuid(null);
        info.setStatus(Constants.SAVESTATUS);
        info.setCreateDate(date);
        info.setCreateUser(user);
        info.setAlterDate(date);
        info.setAlterUser(user);
//		alterBillNumber(SuppliersNature.BIZTYPE, info.getNumber());
        uuid = suppliersNatureDao.save(info);
    }else{
        info.setAlterDate(date);
        info.setAlterUser(user);
        suppliersNatureDao.update(info);
        uuid = info.getUuid();
    }
    
    BaseObject obj = new  BaseObject();
    obj.setCreateDate(date);
    obj.setCreateUser(user);
    obj.setAlterDate(date);
    obj.setAlterUser(user);
    obj.setUuid(uuid);
    obj.setStatus(Constants.SAVESTATUS);
    return obj;
}

  @Override
  public void delByUuids(Object[] uuids) throws DBException, ServiceException {
    for(Object uuid : uuids){
      SuppliersNature suppliersNature  = suppliersNatureDao.get(SuppliersNature.class, uuid.toString());
      suppliersNatureDao.delete(suppliersNature);
  }
}

  @Override
  public SuppliersNature findByUuid(String uuid) throws DBException, ServiceException {
    return suppliersNatureDao.get(SuppliersNature.class, uuid);
    }

  @Override
  public Pager<SuppliersNature> findByCondition(String where, Pager pager) throws DBException,
      ServiceException {
    return  suppliersNatureDao.findByCond(where, pager);
  }
}
